package indi.kider.server.woniubus.api;

import indi.kider.common.model.employee.Employee;
import indi.kider.server.woniubus.model.DevLockCardVo;
import indi.kider.server.woniubus.service.CardService;
import indi.kider.server.woniubus.service.related.AuthcService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pers.vankid.common.model.base.CommonResponse;

/**
 * 卡片控制器
 */
@RestController
@RequestMapping(value = "card")
public class CardControl {


    @Autowired
    private CardService cardService;
    @Autowired
    private AuthcService authcService;

    /**
     * 添加卡信息
     * @param devLockCardVo
     * @return
     */
    @PostMapping("/addCard")
    public CommonResponse addCard(@RequestBody DevLockCardVo devLockCardVo){
        try {
            Employee employee = authcService.getCurrentUser().getData();
            devLockCardVo.setOpenCardUser(employee.getName());
            return cardService.addCard(devLockCardVo);
        } catch (Exception e) {
            return CommonResponse.buildExceptionResponse(e);
        }
    }

    /**
     * 删除卡信息
     * @param devLockCardVo
     * @return
     */
    @PostMapping("/delCard")
    public CommonResponse delCard(@RequestBody DevLockCardVo devLockCardVo){
        try {
            Employee employee = authcService.getCurrentUser().getData();
            devLockCardVo.setClearCardUser(employee.getName());
            return cardService.delCard(devLockCardVo);
        } catch (Exception e) {
            return CommonResponse.buildExceptionResponse(e);
        }
    }

    /**
     * 查找卡信息
     * @param devLockCardVo
     * @return
     */
    @PostMapping("/queryCard")
    public CommonResponse queryCard(@RequestBody DevLockCardVo devLockCardVo){
        try {
            return cardService.queryCard(devLockCardVo);
        } catch (Exception e) {
            return CommonResponse.buildExceptionResponse(e);
        }
    }
}
